package erz.printing.police;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import erz.printing.police.settings.SettingsActivity;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    private View zhianCategory;
    private View xiaofangEntry;
    private View xingshiEntry;
    private View xunwenEntry;
    private View jiechujingEntry;
    private View fankongEntry;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fixPlaceHolderHeight();

        initView();
    }

    private void initView() {
        zhianCategory = findViewById(R.id.zhian_entry);
        zhianCategory.setOnClickListener(this);
        xiaofangEntry = findViewById(R.id.xiaofang_entry);
        xiaofangEntry.setOnClickListener(this);
        xingshiEntry = findViewById(R.id.xingshi_entry);
        xingshiEntry.setOnClickListener(this);
        xunwenEntry = findViewById(R.id.xunwenbilu_entry);
        xunwenEntry.setOnClickListener(this);
        jiechujingEntry = findViewById(R.id.jiechujing_entry);
        jiechujingEntry.setOnClickListener(this);
        fankongEntry = findViewById(R.id.fankong_entry);
        fankongEntry.setOnClickListener(this);
    }

    private void fixPlaceHolderHeight() {
        int height = getActionBarHeight() + getStatusBarHeight();
        View view = findViewById(R.id.place_holder);
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        lp.height = height;
        view.setLayoutParams(lp);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.zhian_entry) {
            startActivity(new Intent(this, ZhianActivity.class));
        }
        else if (id == R.id.xiaofang_entry) {
            Intent intent = new Intent(this, PrintPhotoActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("checkTitle", "消防检查发现隐患");
            bundle.putString("docTemplateNotice", "消防责令改正.html");
            bundle.putString("noticeName", "打印通知书");
            bundle.putString("title", "消防检查");
            bundle.putBoolean("printTitle", true);
            bundle.putBoolean("printExaminer", true);
            intent.putExtras(bundle);
            startActivity(intent);
        }
        else if (id == R.id.xingshi_entry) {
            startActivity(new Intent(this, AnjianActivity.class));
        }
        else if (id == R.id.xunwenbilu_entry) {
            startActivity(new Intent(this, XunWenActivity.class));
        }
        else if (id == R.id.jiechujing_entry) {
            startActivity(new Intent(this, JieJingActivity.class));
        }
        else if (id == R.id.fankong_entry) {
            Intent intent = new Intent(this, PrintPhotoActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("checkTitle", "反恐核查");
            bundle.putString("noticeName", "核查报告");
            bundle.putString("title", "反恐核查");
            intent.putExtras(bundle);
            startActivity(intent);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_option_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.settings:
                startActivity(new Intent(this, SettingsActivity.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

}
